const baseUrl = 'https://kms.hyyj.shop/'   
import store from '../store/index.js'
const request = (url = '', data = {}, type = 'post', header = {
}) => {
	
    return new Promise((resolve, reject) => {
        uni.request({
            method: type,
            url: baseUrl + url,
            data: data,
			   header:{
				   'Authorization':store.state.Authorization
			   }
        }).then((response) => {
			if(response[1].data.Authorization){
				store.commit('UPDATE_AUTH',response[1].data.Authorization)
				// uni.setStorageSync('Authorization',response[1].data.Authorization)
			}
			if(response[1].data.RequestStatus == 200 || response[1].data.RequestStatus == 204){
				uni.hideToast()
				resolve(response[1].data);
			}else if(response[1].data.RequestStatus == 401){
				uni.switchTab({
					url:'/pages/user/user'
				})
				uni.showToast({
					title:'请先登录',
					icon:'none'
				})
			}else{
				uni.showToast({
					title:response[1].data.Message,
					icon:'none'
				})
			}
        }).catch(error => {
            reject(error)
        })
    });
}
export { request } 